package com.example.dev_wang.appfacadedemo.Module.Login.ViewModel;

import com.example.dev_wang.appfacadedemo.AppFacade.MC;
import com.example.dev_wang.appfacadedemo.Module.Login.Interface.IResultCallback;
import com.example.dev_wang.appfacadedemo.Module.Login.Model.UserEntity;
import com.example.puremvc_appfacade.Runs.ViewModel;

/**
 * Created by dev_wang on 2017/2/3.
 */

public class LoginViewModel extends ViewModel {

    String sexText = "性别: ";
    String ageText = "年龄: ";
    String nameText = "姓名: ";

    @Override
    public void initializeViewModel() {
        super.initializeViewModel();
    }

    @Override
    public void setModel(Object model) {
        super.setModel(model);

        if (!model.getClass().equals(UserEntity.class)) {
            return;
        }

        UserEntity entity = (UserEntity)model;
        if (entity.getSex() == 0) {
            sexText += "女";
        }else{
            sexText += "男";
        }

        ageText += entity.getAge();
        nameText += entity.getName();
    }

    public void requestUserLogin(String userName, String userPasswd, IResultCallback callback) {
        if (userName.length() >= 3) {
            callback.onSuccess();
            return;
        }
        callback.onFailed();
    }

    public void requestUserLogout(IResultCallback callback) {
        callback.onSuccess();
    }

    public void requestUserRegister(String userName, String userPasswd, IResultCallback callback){
        if (userName.length() >= 3) {
            callback.onSuccess();
            return;
        }
        callback.onFailed();
    }

    public static LoginViewModel self() {
        return (LoginViewModel) MC.FACADE.getViewModelWithName(LoginViewModel.class.getName());
    }


}
